﻿using System;
using System.ComponentModel;

using Microsoft.WowAddonStudio.FrameXml.Components.Layout;
using Microsoft.WowAddonStudio.FrameXml.Services;

namespace Microsoft.WowAddonStudio.FrameXml.Components.Support
{
    public class FrameXmlContainer : Container
    {
        private readonly FrameXmlFontService fontService;
        private readonly FrameXmlImageService imageService;
        private readonly FrameXmlLayoutEngine layoutEngine;

        /// <summary>
        /// Initializes a new instance of the <see cref="FrameXmlContainer"/> class.
        /// </summary>
        /// <param name="resourceFileLoader">The resource file loader.</param>
        public FrameXmlContainer(ResourceFileLoader resourceFileLoader)
        {
            if (resourceFileLoader == null)
                throw new ArgumentNullException("resourceFileLoader");

            // Initialize services
            fontService = new FrameXmlFontService(resourceFileLoader);
            imageService = new FrameXmlImageService(resourceFileLoader);

            // Initialize layout engine
            layoutEngine = new FrameXmlLayoutEngine();
        }

        /// <summary>
        /// Gets the service object of the specified type, if it is available.
        /// </summary>
        /// <param name="service">The <see cref="T:System.Type"/> of the service to retrieve.</param>
        /// <returns>
        /// An <see cref="T:System.Object"/> implementing the requested service, or null if the service cannot be resolved.
        /// </returns>
        protected override object GetService(Type service)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            if (service == typeof(FrameXmlLayoutEngine))
                return layoutEngine;
            if (service == typeof(FrameXmlImageService))
                return imageService;
            if (service == typeof(FrameXmlFontService))
                return fontService;

            return base.GetService(service);
        }
    }
}
